﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace SqliteWrapper
{
    public class NonQueryCommon
    {
        public SqliteError Query(string nonQuery,string DBPath)
        {
            SqliteError error = new SqliteError() { ErrorText = null, IsProcessSuccess = true };
            SqliteConnectionManager manager = SqliteConnectionManager.Create(DBPath);
            using (SQLiteWriteLock locker = new SQLiteWriteLock(manager.ConnectionString))
            {
                using (SQLiteConnection conn = manager.GetSqliteConnection())
                {
                    conn.Open();
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = nonQuery;
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            error.ErrorText = ex.Message;
                            error.IsProcessSuccess = false;
                        }
                    }
                }
            }
            return error;
        }
    }
}
